/* GUI CONVERTED from icedit5.i (converter v1.76) Fri Apr 26 15:48:53 2002 */
/* icedit5.i - INCLUDE FILE TO EDIT INVENTORY TRANS INPUT                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.10 $                                       */
/* REVISION: 8.5      LAST MODIFIED: 07/31/96   BY: kxn *J12S**/
/* REVISION: 8.5      LAST MODIFIED: 08/02/96   BY: kxn *J13M**/
/* REVISION: 8.5      LAST MODIFIED: 12/17/97   BY: *J252* Viswanathan        */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 09/04/99   BY: *J3KM* G.Latha            */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *D858*                    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.9       BY: Jean Miller           DATE: 04/06/02  ECO: *P056*  */
/* $Revision: 1.10 $  BY: Paul Donnelly  DATE: 12/13/01  ECO: *N16J*  */

/*V8:ConvertMode=Maintenance                                                  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/**************************************************************/
/* {&transtype}  ""ISS-SO"", ""RCT-PO"" etc.
   {&site}
   {&location}
   {&part}
   {&lotserial}
   {&lotref}
   {&quantity}   In terms of pt_um
   {&um}         The issue or receipt um
   {&trnbr}      Order number
   {&trline}     WO Lot or PO line
   {&overissue_check}      Used to control the check of overissue
                           when doing a SO issue where a receipt transaction
                           is done simultaneously, ie configured product
                           receipts and final assy receipts, which would
                           result in a net-zero issue.
*/
/***********************************************************************/

/*NOTE: CHANGES MADE TO THIS INCLUDE FILE MAY NEED TO BE          */
         /*MADE TO ICEDIT2.I ALSO.                          */

find first icc_ctrl no-lock.
find first clc_ctrl no-lock no-error.
if not available clc_ctrl then do:
   {gprun.i ""gpclccrt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   find first clc_ctrl no-lock.
end.

find loc_mstr where loc_site = {&site}
                and loc_loc = {&location}
no-lock no-error.

find in_mstr where in_site = {&site} and in_part = {&part}
no-lock no-error.

find pt_mstr where pt_part = {&part}
no-lock no-error.

find ld_det where ld_site = {&site}
              and ld_loc = {&location}
              and ld_lot = {&lotserial}
              and ld_ref = {&lotref}
              and ld_part = {&part}
no-lock no-error.

{icedit1.i
   &site="{&site}"
   &part="{&part}"
   &lotserial="{&lotserial}"
   &quantity="{&quantity}"
   &um="{&um}"
   &transtype="{&transtype}"}

/* MOVED RESTRICTED TRANSACTION VALIDATION TO worcat01.p FOR        */
if {&transtype} <> "RCT-WO" then do:

   /* THE FOLLOWING CODE IS TO CHECK WHETHER INVENTORY TRANSACTION */
   /* STATUS CODE FOUND IN IN_MSTR/PT_MSTR IS DEFINED IN           */
   /* INVENTORY STATUS MASTER.                                     */
   if available in_mstr and {&transtype}    = "RCT-PO" and
      in_rctpo_active = yes
   then
      find is_mstr where is_status = in_rctpo_status no-lock no-error.

   else
   if available pt_mstr and {&transtype}    = "RCT-PO" and
      pt_rctpo_active = yes
   then
      find is_mstr where is_status = pt_rctpo_status no-lock no-error.

   else
   /* MAKE SURE STATUS CODE EXISTS AND TRANSTYPE ALLOWED */
   if available ld_det then
      find is_mstr where is_status = ld_status no-lock no-error.
   else
   if available loc_mstr then
      find is_mstr where is_status = loc_status no-lock no-error.
   else
      find is_mstr where is_status = si_status no-lock no-error.

   if not available is_mstr then do:
      {pxmsg.i &MSGNUM=361 &ERRORLEVEL=3}
      undo, retry.
   end.

   find isd_det no-lock where isd_tr_type = {&transtype}
                          and isd_status = is_status
   no-error.

   if available isd_det
   then do:
      if batchrun = yes  and isd_bdl_allowed <> yes
      then do:
         /* ISD_STATUS WILL CONTAIN THE RESTRICTED STATUS CODE */
         /* RESTRICTED TRANSACTION FOR STATUS CODE: */
         {pxmsg.i &MSGNUM=373 &ERRORLEVEL=3 &MSGARG1=isd_status}
         undo, retry.
      end.
      if batchrun <> yes
      then do:
         /* ISD_STATUS WILL CONTAIN THE RESTRICTED STATUS CODE */
         /* RESTRICTED TRANSACTION FOR STATUS CODE: */
         {pxmsg.i &MSGNUM=373 &ERRORLEVEL=3 &MSGARG1=isd_status}
         undo, retry.
      end.
   end.

end. /* IF {&transtype} <> "RCT-WO" */

/*CHECK THAT XFER ACCOUNTS ARE DEFINED IN A MULTI-SITE ENVIRONMENT*/
if si_xfer_acct = "" or icc_xclr_acct = "" then do:
   find first si_mstr where si_site > {&site} no-lock no-error.
   if not available si_mstr then
      find last si_mstr where si_site < {&site} no-lock no-error.
   if available si_mstr then do:
      {pxmsg.i &MSGNUM=5226 &ERRORLEVEL=3} /*inv ctrl xfer accts not defined*/
      undo, retry.
   end.
   find first si_mstr where si_site = {&site} no-lock no-error.
end.

         /*CHECK THAT SITE IS ATTACHED TO THIS DATABASE*/
         if si_db <> global_db then do:
            {mfmsg.i 5421 3} /*site is not assigned to this database*/
            undo, retry.
         end.
         /*END ADDED SECTION*/

/* CHECKING FOR LOCATION */
if available pt_mstr and not available loc_mstr then do:
   /* WARN IF LOCATION DOESNT EXIST */
   if {&action} + 0 = 0 then do:
      if si_auto_loc then do:
         {pxmsg.i &MSGNUM=709 &ERRORLEVEL=2}
      end.
      else do:
         {pxmsg.i &MSGNUM=709 &ERRORLEVEL=3}
      end.
      if si_auto_loc = no then undo, retry.
   end.
   else if not si_auto_loc then do:
      {pxmsg.i &MSGNUM=709 &ERRORLEVEL=3}
      undo, retry.
   end.
end.

if ({&lotserial} <> "") and (clc_lotlevel <> 0) then do:

   find lot_mstr no-lock where lot_part = {&part}
      and lot_serial = {&lotserial} no-error.

   if available lot_mstr then do:
      if ({&trnbr} <> "" and lot_nbr <> {&trnbr})
         or ({&trline} <> "" and lot_line <> {&trline})
      then do:
         {pxmsg.i &MSGNUM=2707 &ERRORLEVEL=3}  /* WO or LINE DOES NOT MATCH */
         undo, retry.
      end.
   end. /* IF AVAILABLE LOT_MSTR */

   else if (({&transtype} begins "R" and {&quantity} > 0)
        or  ({&transtype} = "ISS-RMA" and {&quantity} < 0))
   then do:
      {gprun.i ""gplotwup.p""
         "({&lotserial},
           {&part},
           output trans-ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if not trans-ok then undo, retry.
   end. /* ELSE IF {&TRANSTYPE} BEGINS "R" */

   else if ((({&transtype} begins "I") and ({&quantity} <> 0))
        or ({&transtype} begins "R" and {&quantity} < 0))
   then do:
      /* LOT/SERIAL DOES NOT EXISTS - NO ISSUE ALLOWED */
      {pxmsg.i &MSGNUM=2704 &ERRORLEVEL=3}
      undo, retry.
   end. /* ELSE IF {&TRANSTYPE} BEGINS "I" .... */

end. /* IF {&LOTSERIAL} <> "" AND */

/* CHECKING FOR ISSUES */
if ({&transtype} begins "I" and {&quantity} > 0)
or ({&transtype} begins "R" and {&quantity} < 0)
then do:
   if available ld_det then do:
      if ld_expire < today + icc_iss_days
         and {&transtype} <> "ISS-TR"   /*do not include transfers*/
         and {&transtype} <> "ISS-CHL"  /*do not include status change*/
         and {&transtype} <> "ISS-GIT"  /*do not include transit issue*/
         and {&transtype} <> "RCT-TR"   /*do not include transfers*/
         and {&transtype} <> "RCT-CHL"  /*do not include status change*/
         and {&transtype} <> "RCT-GIT"  /*do not include transit issue*/
      then do:
         find lot_mstr no-lock where lot_part = {&part}
            and lot_serial = {&lotserial} no-error.
         if (not available lot_mstr) or (lot_trans <> {&transtype})
         then do:
            {pxmsg.i &MSGNUM=76 &ERRORLEVEL=3}
            /* MAKE SURE NOT EXPIRED */
            undo, retry.
         end. /* IF (NOT AVAILABLE LOT_MSTR) OR ... */
      end.
   end.

   /* MOVED THE VALIDATION FOR NEGATIVE RECEIPTS TO worcat01.p */
   /* FOR TRANSACTION TYPE "RCT-WO"                            */

   if {&transtype} <> "RCT-WO"
   then do:

      if not is_overissue
         {&overissue_check}
         and (not available ld_det
         or (({&transtype} begins "I" and ld_qty_oh < {&quantity})
         or  ({&transtype} begins "R" and ld_qty_oh < {&quantity} * -1)))
      then do:
         /* MAKE SURE SUFFICIENT QTY */
         msg-arg = string(if available ld_det then ld_qty_oh else 0).
         {pxmsg.i &MSGNUM=208 &ERRORLEVEL=3
                  &MSGARG1=msg-arg}
         undo, retry.
      end.

   end. /* IF {transtype} <> "RCT-WO" */

   if {&action} + 0 = 0  then do:
      if not available ld_det then do:
         {pxmsg.i &MSGNUM=242 &ERRORLEVEL=2}
         /*WARN IF RECORD DOES NOT EXIST*/
      end.
      else do:
         if (({&transtype} begins "I" and ld_qty_oh < {&quantity})
            or  ({&transtype} begins "R" and ld_qty_oh < {&quantity} * -1))
            {&overissue_check}
            and {&transtype} <> "RCT-WO"
         then do:
            /* Warning if insufficient quantity */
            {pxmsg.i &MSGNUM=208 &ERRORLEVEL=2 &MSGARG1=ld_qty_oh}
         end.
      end.
   end.
end.

/* CHECKING FOR RECEIPTS */
if ({&transtype} begins "R" and {&quantity} > 0)
or ({&transtype} begins "I" and {&quantity} < 0)
or ({&transtype} begins "CYC")
then do:

   /* DO NOT CHECK LOCATION TYPES FOR WAREHOUSING INTERFACE */
   if not can-find(whl_mstr where whl_site = {&site}
                              and whl_loc = {&location} no-lock)
   then do:
      if available pt_mstr and pt_loc_type <> "" then
      if ((available loc_mstr and loc_type <> pt_loc_type)
         or (not available loc_mstr)) then do:
         {pxmsg.i &MSGNUM=240 &ERRORLEVEL=3}
         undo, retry.
      end.
   end.  /* IF NOT WAREHOUSE INTERFACE LOCATION */

   if available loc_mstr and loc_single then do:
      /*Added loc__qad01 (single lot/serial flag to parameter list */
      {gprun.i ""gploc01.p""
         "(si_site,loc_loc, {&part},{&lotserial},{&lotref},
           loc__qad01,
           output trmsg)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if trmsg <> 0 then do:
         {pxmsg.i &MSGNUM=245 &ERRORLEVEL=3}
         undo, retry.
      end.
   end.
end.

/* CHECKING FOR DUPLICATE SERIAL NUMBER ON RECEIPTS */
if ({&transtype} begins "R" and {&transtype} <> "RCT-TR" and {&quantity} > 0)
or ({&transtype} begins "I" and {&transtype} <> "ISS-TR" and {&quantity} < 0)
then do:

   if available pt_mstr and pt_lot_ser = "S" then do:

      find first ld_det where ld_part = {&part}
         and ld_lot = {&lotserial} and ld_qty_oh > 0 no-lock no-error.

      /* WARNING IF SERIAL EXISTS */
      if available ld_det
      then do:
         msg-arg = ld_site + ", " + ld_loc.
         {pxmsg.i &MSGNUM=79 &ERRORLEVEL=3 &MSGARG1=msg-arg}
         undo, retry.
      end.

   end.

end.

/* CHECKING FOR DUPLICATE SERIAL NUMBER ON RECEIPTS */
if clc_lotlevel > 0
   and (({&transtype} = "RCT-TR"
   and {&quantity} > 0)
   or ({&transtype} = "ISS-TR"
   and {&quantity} < 0))
then do:

   if available pt_mstr and pt_lot_ser = "S" then do:
      find ld_det where ld_site = {&site} and ld_part = {&part}
         and ld_loc = {&location} and ld_ref = {&lotref}
         and ld_lot = {&lotserial}  no-lock no-error.
      /* WARNING IF SERIAL EXISTS */
      if available ld_det and ld_qty_oh > 0
      then do:
         msg-arg = ld_site + ", " + ld_loc.
         {pxmsg.i &MSGNUM=79 &ERRORLEVEL=3 &MSGARG1=msg-arg}
         undo, retry.
      end.
   end.

end.
